﻿using Inaction.DbSchame;
using System;

namespace Inaction.Mapping
{
    [AttributeUsage(AttributeTargets.Class)]
    public class TableAttribute : Attribute
    {
        #region 属性
        public string TableName { get; set; }
        string friendlyName;
        public string FriendlyName
        {
            get
            {
                if (string.IsNullOrEmpty(friendlyName)
                    && Table != null
                    && !string.IsNullOrEmpty(Table.DisplayName))
                    friendlyName = Table.DisplayName;
                return friendlyName;
            }
            set { friendlyName = value; }
        }
        public string SelectView { get; set; }

        public string SelectSql { get; set; }

        Table table;
        public Table Table
        {
            get
            {
                if (table == null) table = DbProvider.Instance.GetTable(TableName);
                return table;
            }
        }
        #endregion

        public TableAttribute(string tableName)
        {
            this.TableName = tableName;
        }
    }
}
